<?php


namespace app\admin\server\user;


use app\admin\ServerBase;
use app\admin\model\view\UserWriterVerifyUserView;
use app\admin\model\UserWriterVerifyModel;
class WriterVerifyServer extends ServerBase
{

    protected $model;
    protected $request;
    function __construct($request)
    {
        $this->request=$request;
        $this->model=new UserWriterVerifyUserView();
    }
    function getList(){
        $limit=check_request($this->request,"limit")?$this->request['limit']:15;
        $field="*";
        $res=$this->model->getList($this->request,$field,$limit);
        if($res){
            show_json('code_common.success',$res);
        }else{
            show_json('code_common.not_find');
        }
    }
    function verify(){
        if(!check_request($this->request,'id')){
            show_json("adminMessage.writer_verify.no_id");
        }
        if(!check_request($this->request,'status')){
            show_json("adminMessage.writer_verify.no_status");
        }
        $verify=$this->model->findById($this->request['id']);
        if(empty($verify)){
            show_json('code_common.illegal');
        }
        if($verify['status']==-1||$verify['status']==2){
            show_json("adminMessage.writer_verify.already");
        }
        $res=$this->model->verify($this->request,$verify);
        $res?show_json('code_common.success'):show_json('code_common.error');
    }
    
    function getWriteTime($data){
    	$_ids=array_column($data,'id');
    	$_where[]=["id","in",$_ids];
    	$_field="id,uid,verify_time";
    	$_write_verify_server=new UserWriterVerifyModel();
    	$_writer_verify_data=$_write_verify_server->selectWriteData($_where,$_field);
    	$_new_data=[];
    	if(!empty($_writer_verify_data))
    	{
    		foreach($_writer_verify_data as $k=>$v){
    			$_new_data[$v['uid']]=$v;
    		}
    	}
    	foreach($data as $k=>$v){
			if(isset($_new_data[$v['id']])){
				$data[$k]['writer_verify_time']=!empty($_new_data[$v['id']]['verify_time'])?date('Y-m-d H:i',$_new_data[$v['id']]['verify_time']):'-';
			}else{
				$data[$k]['writer_verify_time']='-';
			}
		}
    	return $data;
    }
}